package online.misscl.lsy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import online.misscl.lsy.entity.ConsultationAnnouncement;
import online.misscl.lsy.entity.dto.vo.ConsultationAnnouncementVo;
import online.misscl.lsy.mapper.ConsultationAnnouncementMapper;
import online.misscl.lsy.service.ConsultationAnnouncementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import online.misscl.lsy.util.PageUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 咨询公告表 服务实现类
 * </p>
 *
 * @author misscl
 * @since 2023/03/11 11:14
 */
@Service
public class ConsultationAnnouncementServiceImpl extends ServiceImpl<ConsultationAnnouncementMapper, ConsultationAnnouncement> implements ConsultationAnnouncementService {


    @Override
    public Page<ConsultationAnnouncement> annoList(Integer pageSize, Integer pageNum) {
        List<ConsultationAnnouncement> list = list();
        return PageUtil.getPages(pageNum,pageSize,list);
    }

    @Override
    public List<ConsultationAnnouncementVo> getConsultationAnnouncement(String type) {
        LambdaQueryWrapper<ConsultationAnnouncement> consultationAnnouncementLambdaQueryWrapper = new LambdaQueryWrapper<>();
        consultationAnnouncementLambdaQueryWrapper.eq(ConsultationAnnouncement::getAnnouncementType,type);
        List<ConsultationAnnouncement> consultationAnnouncements = baseMapper.selectList(consultationAnnouncementLambdaQueryWrapper);
        List<ConsultationAnnouncementVo> voList = new ArrayList<>();
        for(ConsultationAnnouncement announcement:consultationAnnouncements){
            ConsultationAnnouncementVo consultationAnnouncementVo = new ConsultationAnnouncementVo();
            BeanUtils.copyProperties(announcement,consultationAnnouncementVo);
            voList.add(consultationAnnouncementVo);
        }
        return voList;
    }
}
